﻿using System;
using System.Runtime.Serialization;

using BLToolkit.Mapping;

using EMan.Common.EnterpriseStructure;

using TrueCode.Core.EditableEntity;
using TrueCode.Core.Validation;

using NotNullAttribute = TrueCode.Core.Aspects.NotNullAttribute;
using CanBeNullAttribute = TrueCode.Core.Aspects.CanBeNullAttribute;

namespace EMan.Common.WorkTasks
{
  [DataContract(IsReference = true)]
  [MapField("EmployeeId", "Employee.Id")]
  public class WorkTask : ReferenceEntity< WorkTask >
  {
    public WorkTask( [NotNull] string summary, string fullText, [CanBeNull] Employee assignee, DateTime dueDate )
    {
      if( summary == null ) throw new ArgumentNullException( "summary" );

      Summary = summary;
      FullText = fullText ?? string.Empty;
      Employee = assignee;
      DueDate = dueDate;
    }

    [NotNull]
    [DataMember]
    [Validate.NotEmpty, Validate.MaxLength( 100 )]
    [Editable(EditableMode.All)]
    public string   Summary   { get; set; }
    
    [CanBeNull]
    [DataMember]
    [NullValue( "" )]
    [Validate.MaxLength( 500 )]
    [Editable(EditableMode.All)]
    public string   FullText  { get; set; }


    [CanBeNull]
    [DataMember]
    [Editable(EditableMode.All)]
    public Employee Employee  { get; set; }

    [DataMember]
    [Editable(EditableMode.All)]
    public DateTime DueDate { get; set; }

    [Obsolete("For BLT and tests")]
    public WorkTask(){}
  }
}